var limsPageContentConfig = Gikam.getPageObject({

    pageConfigUrl: IFM_CONTEXT + '/secure/basemodule/basedata/pageconfigs',

    getLoginPageFields: function () {
        var _this = this;
        return [{
            field: 'title',
            title: 'T_LIMS_PAGE_CONTENT_CONFIG.TITLE',
            validators: ['strLength[0,20]']
        }, {
            field: 'enTitle',
            title: 'T_LIMS_PAGE_CONTENT_CONFIG.ENTITLE',
            validators: ['strLength[0,20]']
        }, {
            field: 'copyright',
            title: 'T_LIMS_PAGE_CONTENT_CONFIG.COPYRIGHT',
            validators: ['strLength[0,20]']
        }, {
            field: 'enCopyright',
            title: 'T_LIMS_PAGE_CONTENT_CONFIG.ENCOPYRIGHT',
            validators: ['strLength[0,20]']
        }, {
            field: 'ext$.logopic',
            type: 'image',
            title: 'T_LIMS_PAGE_CONTENT_CONFIG.LOGOPIC_LOGIN',
            height: 60,
            onClick: function () {
                _this.editPage.uploadLogoPic('lims-logpage-config-form', 1);
            },
            onCloseClick: function () {
                Gikam.post(IFM_CONTEXT + '/core/module/item/files/queries', Gikam.getJsonWrapper({
                    f: {
                        targetId: 'T_LIMS_PAGE_CONTENT_CONFIG$1',
                        bizCategory_SEQ: 'LOGOPIC',
                    },
                    n: -1,
                    s: 50
                })).done(function (fileList) {
                    if (Gikam.isNotEmpty(fileList.rows)) {
                        Gikam.getComp('lims-logpage-config-form').setData({ext$: {logopic: ''}});
                        var imageUrl = Gikam.IFM_CONTEXT + '/core/module/item/files';
                        var imageParams = Gikam.getJsonWrapper('', ['', [{id: fileList.rows[0].id}]]);
                        Gikam.del(imageUrl, imageParams);
                    }
                })
            }
        }];
    },

    getIndexPageFields: function () {
        var _this = this;
        return [{
            field: 'title',
            title: 'T_LIMS_PAGE_CONTENT_CONFIG.TITLE',
            validators: ['strLength[0,20]']
        }, {
            field: 'enTitle',
            title: 'T_LIMS_PAGE_CONTENT_CONFIG.ENTITLE',
            validators: ['strLength[0,20]']
        }, {
            field: 'ext$.logopic',
            type: 'image',
            title: 'T_LIMS_PAGE_CONTENT_CONFIG.LOGOPIC',
            height: 60,
            onClick: function () {
                _this.editPage.uploadLogoPic('lims-indexpage-config-form', 2);
            },
            onCloseClick: function () {
                Gikam.post(IFM_CONTEXT + '/core/module/item/files/queries', Gikam.getJsonWrapper({
                    f: {
                        targetId: 'T_LIMS_PAGE_CONTENT_CONFIG$2',
                        bizCategory_SEQ: 'LOGOPIC',
                    },
                    n: -1,
                    s: 50
                })).done(function (fileList) {
                    if (Gikam.isNotEmpty(fileList.rows)) {
                        Gikam.getComp('lims-indexpage-config-form').setData({ext$: {logopic: ''}});
                        var imageUrl = Gikam.IFM_CONTEXT + '/core/module/item/files';
                        var imageParams = Gikam.getJsonWrapper('', ['', [{id: fileList.rows[0].id}]]);
                        Gikam.del(imageUrl, imageParams);
                    }
                })
            }
        }, {
            field: 'ext$.logopicmain',
            type: 'image',
            title: 'T_LIMS_PAGE_CONTENT_CONFIG.LOGOPIC_MAIN',
            height: 60,
            onClick: function () {
                _this.uploadLogoPic2('lims-indexpage-config-form', 2);
            },
            onCloseClick: function () {
                Gikam.post(IFM_CONTEXT + '/core/module/item/files/queries', Gikam.getJsonWrapper({
                    f: {
                        targetId: 'T_LIMS_PAGE_CONTENT_CONFIG$2',
                        bizCategory_SEQ: 'LOGOPIC_MAIN',
                    },
                    n: -1,
                    s: 50
                })).done(function (fileList) {
                    if (Gikam.isNotEmpty(fileList.rows)) {
                        Gikam.getComp('lims-indexpage-config-form').setData({ext$: {logopicmain: ''}});
                        var imageUrl = Gikam.IFM_CONTEXT + '/core/module/item/files';
                        var imageParams = Gikam.getJsonWrapper('', ['', [{id: fileList.rows[0].id}]]);
                        Gikam.del(imageUrl, imageParams);
                    }
                })
            }
        }];
    },

    uploadLogoPic2 : function(idStr, bizId) {
        var configForm = Gikam.getComp(idStr);
        Gikam.post(IFM_CONTEXT + '/core/module/item/files/queries', Gikam.getJsonWrapper({
            f : {
                targetId : 'T_LIMS_PAGE_CONTENT_CONFIG$' + bizId,
                bizCategory_SEQ : 'LOGOPIC_MAIN'
            },
            n : -1,
            s : 50
        })).done(function(r) {
            if (r.total > 0) {
                Gikam.confirm('GIKAM.BUTTON.CONFIRM', 'LIMS.PAGE.CONFIG.LOGO.OVERRIDE', function() {
                    Gikam.create('simpleUploader', {
                        id : 'page-config-logo-pic-uploader',
                        dbTable : 'T_LIMS_PAGE_CONTENT_CONFIG',
                        bizId : bizId,
                        bizCategory : 'LOGOPIC_MAIN',
                        accept : 'image',
                        multiple : false,
                        onAfterClose : function(fileList) {
                            if (fileList.length > 0) {
                                Gikam.del(IFM_CONTEXT + '/core/module/item/files', Gikam.getJsonWrapper(null, [ '', r.rows ]));
                                Gikam.getJson(Gikam.printf(IFM_CONTEXT + '/core/module/item/files/{id}', {
                                    id : fileList[0].id
                                })).done(function(r) {
                                    configForm.setData({
                                        ext$ : {
                                            logopicmain : r.downloadUrl
                                        }
                                    }, false)
                                });
                            }
                        }
                    });
                })
            } else {
                Gikam.create('simpleUploader', {
                    id : 'page-config-logo-pic-uploader',
                    dbTable : 'T_LIMS_PAGE_CONTENT_CONFIG',
                    bizId : bizId,
                    bizCategory : 'LOGOPIC_MAIN',
                    accept : 'image',
                    multiple : false,
                    onAfterClose : function(fileList) {
                        if (fileList.length === 0) {
                            return;
                        }
                        Gikam.getJson(Gikam.printf(IFM_CONTEXT + '/core/module/item/files/{id}', {
                            id : fileList[0].id
                        })).done(function(r) {
                            configForm.setData({
                                ext$ : {
                                    logopicmain : r.downloadUrl
                                }
                            }, false)
                        });
                    }
                });
            }
        });
    },

});
